<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            border: 1px solid red;
            border-radius: 10px;
            display: flex;
            margin: 20px;
            justify-content: center;
            align-items: center;
        }

        .content {
            display: flex;
            flex-wrap: wrap;
            width: 600px;
            background-color: #cccccc;
        }
    </style>
</head>
<body>
<div class="content">
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
    <div class="box">4</div>
    <div class="box">5</div>
    <div class="box">6</div>
    <div class="box">7</div>
    <div class="box">8</div>
    <div class="box">9</div>
    <div class="box">10</div>
    <div class="box">11</div>
    <div class="box">12</div>
    <div class="box">13</div>
    <div class="box">14</div>
    <div class="box">15</div>
    <div class="box">16</div>
    <div class="box">17</div>
    <div class="box">18</div>
    <div class="box">19</div>
    <div class="box">20</div>
</div>
<script>

    let enabled = true;

    function expensiveOperation() {
        console.log('Invoked at', Date.now());
    }

    window.addEventListener('scroll', () => {
        if (enabled) {
            enabled = false;
            requestAnimationFrame(expensiveOperation)
            setTimeout(() => enabled = true, 500)
        }
    })
</script>
</body>
</html>